home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE13 / COMPRESS / COMPRESS.ZIP / COMPMAIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-08-09  |  23.7 KB  |  692 lines

  1. (*
  2.   CompDemo V2.5 for TCompress Components V2.5
  3.  
  4.   Note: This demo is currently saved in Delphi 2.0 format -- see the notes below
  5.   for minor adaptations required to compile it with Delphi 1.0.
  6.  
  7.   You are free to amend, adjust, improve, update, borrow, alter and muck about
  8.   with this demonstration program at will.
  9.  
  10.   However, if you redistribute the amended source together with the TCompress
  11.   components, please be sure to include ALL the files that came with it
  12.   (incl. Compress.hlp, Readme.txt and the ORIGINAL COMPDEMO source).  Thanks.
  13.  
  14.   Hint: To find the code which makes use of the TCompress components, search
  15.   for Compress1, CDBImage1 and CDBMemo1 references...  At some point, you may
  16.   also want to modify this demo to play with the Key, TargetPath and
  17.   MakeDirectories properties of the TCompress component (all new in V2.5).
  18.  
  19.   USING THIS DEMO with Delphi V1.0:
  20.   1. Copy COMPDEMO.DPR, COMPMAIN.PAS and COMPMAIN.DFM to a new directory
  21.   2. Load Delphi 1.0, install Compress/Compctrl and load the new project
  22.   3. Ignore errors about duplicated components and Blobtype properties (not in Delphi 1.0)
  23.   4. In the CheckFile event handler, change the filepath type from string
  24.      (Delphi 2.0) to OpenString (Delphi 1.0). Don't forget to do this in
  25.     the method declaration as well as its implementation.
  26.   5. Compile and go.  Be aware that you may need to add special filename
  27.      handling in Checkfile to deal with any archives already compressed with
  28.      looong (Win32/Delphi 2.0) filenames in them. Basically, just truncate to
  29.      a suitable 8.3 format name.
  30.  
  31.   Enjoy.
  32. *)
  33.  
  34. {$D-}   { Don't need debugging info, thanks... }
  35. unit Compmain;
  36.  
  37. interface
  38.  
  39. uses
  40.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  41.   Forms, Dialogs, Compress, StdCtrls, DB, DBTables, DBCtrls
  42.   ,CompCtrl, ExtCtrls, Buttons, FileCtrl, Mask;
  43.  
  44.  
  45. type
  46.   TForm1 = class(TForm)
  47.     Table1: TTable;
  48.     DBNavigator1: TDBNavigator;
  49.     DataSource1: TDataSource;
  50.     Compress1: TCompress;
  51.     Table1SpeciesNo: TFloatField;
  52.     Table1Category: TStringField;
  53.     Table1Common_Name: TStringField;
  54.     Table1SpeciesName: TStringField;
  55.     Table1Lengthcm: TFloatField;
  56.     Table1Length_In: TFloatField;
  57.     CMethod: TRadioGroup;
  58.     Memo2: TMemo;
  59.     Shape1: TShape;
  60.     GroupBox1: TGroupBox;
  61.     FL: TFileListBox;
  62.     DL: TDirectoryListBox;
  63.     DCB: TDriveComboBox;
  64.     ArchiveGroup: TGroupBox;
  65.     ArchiveLabel: TLabel;
  66.     archivefile: TEdit;
  67.     Label2: TLabel;
  68.     ListBox1: TListBox;
  69.     Fishname: TDBEdit;
  70.     Memo4: TMemo;
  71.     Memo3: TMemo;
  72.     Memo5: TMemo;
  73.     Memo6: TMemo;
  74.     DBText1: TDBText;
  75.     Memo1: TMemo;
  76.     Button1: TButton;
  77.     Panel1: TPanel;
  78.     Bevel1: TBevel;
  79.     Time: TLabel;
  80.     Percentage: TLabel;
  81.     TimeLabel: TLabel;
  82.     Label7: TLabel;
  83.     Trashcan: TImage;
  84.     Image1: TImage;
  85.     Button2: TButton;
  86.     CDBImage1: TCDBImage;
  87.     CDBMemo1: TCDBMemo;
  88.     CDBImage1Graphic: TCGraphicField;
  89.     procedure CompressOneFile(var fname: String);
  90.     procedure ResetFileInfo;
  91.     function GetDir: string;
  92.     function GetDummyFilename(generatefrom: string; ext: string): string;
  93.     procedure handleDropField(Source: TObject; archivetoo: Boolean);
  94.     procedure CompressFiles;
  95.     function getCompressionMethod: TCompressionMethod;
  96.     procedure showInfo;
  97.     procedure FormCreate(Sender: TObject);
  98.     procedure showfiles;
  99.     procedure ExpandDelete(Operation: TCProcessMode; All: Boolean);
  100.     procedure archivefileChange(Sender: TObject);
  101.     procedure CMethodClick(Sender: TObject);
  102.     procedure DLDragOver(Sender, Source: TObject; X, Y: Integer;
  103.       State: TDragState; var Accept: Boolean);
  104.     procedure CDBImage1DragOver(Sender, Source: TObject; X, Y: Integer;
  105.       State: TDragState; var Accept: Boolean);
  106.     procedure CDBImage1DragDrop(Sender, Source: TObject; X, Y: Integer);
  107.     procedure CDBMemo1DragOver(Sender, Source: TObject; X, Y: Integer;
  108.       State: TDragState; var Accept: Boolean);
  109.     procedure CDBMemo1DragDrop(Sender, Source: TObject; X, Y: Integer);
  110.     procedure CDBImage1MouseDown(Sender: TObject; Button: TMouseButton;
  111.       Shift: TShiftState; X, Y: Integer);
  112.     procedure CDBMemo1MouseDown(Sender: TObject; Button: TMouseButton;
  113.       Shift: TShiftState; X, Y: Integer);
  114.     procedure archivefileDragOver(Sender, Source: TObject; X, Y: Integer;
  115.       State: TDragState; var Accept: Boolean);
  116.     procedure archivefileDragDrop(Sender, Source: TObject; X, Y: Integer);
  117.     procedure DLDragDrop(Sender, Source: TObject; X, Y: Integer);
  118.     procedure TrashcanDragDrop(Sender, Source: TObject; X, Y: Integer);
  119.     procedure FormDestroy(Sender: TObject);
  120.     procedure ListBox1Click(Sender: TObject);
  121.     procedure Table1AfterPost(DataSet: TDataset);
  122.     procedure Button1Click(Sender: TObject);
  123.     procedure FLClick(Sender: TObject);
  124.     procedure Compress1CheckFile(var filepath: String;
  125.       mode: TCProcessMode);
  126.     procedure Panel1Click(Sender: TObject);
  127.     procedure FormClick(Sender: TObject);
  128.     procedure GroupBox1Click(Sender: TObject);
  129.     procedure TrashcanDragOver(Sender, Source: TObject; X, Y: Integer;
  130.       State: TDragState; var Accept: Boolean);
  131.     procedure Button2Click(Sender: TObject);
  132.     procedure Compress1ShowProgress(var PercentageDone: Longint);
  133.   private
  134.     { Private declarations }
  135.   public
  136.     { Public declarations }
  137.   end;
  138.  
  139. var
  140.   Form1: TForm1;
  141.  
  142. implementation
  143.  
  144. {$R *.DFM}
  145.  
  146. var FileList: TStringList; { holds information about our archive files }
  147.     saveCompressionMethod: Integer; { see ListBox1.click }
  148.  
  149. const ShowFileInfoColor :Tcolor = clGray; { see Listbox1.click }
  150.  
  151. { Example of accessing the TCompress performance properties }
  152. procedure Tform1.showinfo;
  153. begin
  154.    ResetFileInfo;
  155.    Time.caption:=Format('%-5.1fsecs',[Compress1.CompressionTime/1000.0]{[f]});
  156.    Percentage.caption:=IntToStr(Compress1.CompressedPercentage)+'%';
  157. end;
  158.  
  159. { Example of a progress event (new in TCompress 2.0) }
  160. procedure TForm1.Compress1ShowProgress(var PercentageDone: Longint);
  161. begin
  162.    Percentage.caption:=IntToStr(PercentageDone)+'%';
  163.    Application.ProcessMessages;
  164.   { you may have *other* uses for this every-8K-read event...  In fact, in V2.5
  165.     if you set PercentageDone to -1, it will cause compression to end at the
  166.     point reached. If so, delete from the archive the compressed file
  167.     which was created before the abort  }
  168. end;
  169.  
  170. { Example of getting a list of files in a multi-file archive }
  171. procedure TForm1.showfiles;
  172. begin
  173.   listbox1.clear;
  174.   FileList.clear;
  175.   if not FileExists(archivefile.Text) then exit;
  176.   Compress1.ScanCompressedFile(ArchiveFile.Text,Filelist);
  177.   ListBox1.Items.addStrings(FileList); { and File info objects are
  178.                             there too -- see ListBox1Click and FormDestroy }
  179. end;
  180.  
  181. { Example of expanding/deleting one or more files from a multi-file archive }
  182. procedure TForm1.ExpandDelete(Operation: TCProcessMode; All: Boolean);
  183. var s: Tstringlist;
  184.   count: Integer;
  185. begin
  186.   if (All and (Listbox1.Items.count > 0)) or (Listbox1.selcount>0) then { something is... }
  187.   begin
  188.      s:=Tstringlist.create;
  189.      try
  190.         if All then
  191.            s.addStrings(ListBox1.Items)
  192.         else
  193.            for count :=0 to Listbox1.ITems.count-1 do
  194.             if Listbox1.selected[count] then
  195.               s.add(Listbox1.items[count]);
  196.         if Operation=cmExpand then { expand }
  197.           compress1.expandfiles(ArchiveFile.Text,s)
  198.         else
  199.           compress1.deletefiles(ArchiveFile.Text,s);
  200.         showinfo;
  201.         showfiles; { also clears selections... }
  202.      finally
  203.         s.free;
  204.         Screen.Cursor := crDefault;
  205.      end;
  206.   end;
  207. end;
  208.  
  209. { Example of compressing a SINGLE file into an archive }
  210. procedure TForm1.CompressOneFile(var fname: String);
  211. begin
  212.   Compress1.CompressFile(ArchiveFile.Text,fname,getCompressionMethod);
  213.   showInfo;
  214.   showfiles;
  215.   Screen.Cursor := crDefault;
  216.   SysUtils.DeleteFile(fname); { because for this example we're creating TEMP files only... }
  217. end;
  218.  
  219. { Example of compressing MULTIPLE files into an archive }
  220. procedure TForm1.CompressFiles;
  221. var s: Tstringlist;
  222.     Count: Integer;
  223. begin
  224.   if FL.selcount>0 then { something is... }
  225.   begin
  226.     s:=TStringlist.Create;
  227.     try
  228.       for count :=0 to FL.Items.count-1 do
  229.         if FL.selected[count] then
  230.           s.add(FL.items[count]);
  231.       Compress1.CompressFiles(ArchiveFile.Text,s,getCompressionMethod);
  232.       showInfo;
  233.       showfiles;
  234.     finally;
  235.        s.free;
  236.        Screen.Cursor := crDefault;
  237.     end;
  238.   end;
  239. end;
  240.  
  241. { Examples of setting/loading/shifting image blobs }
  242. procedure TForm1.CDBImage1DragDrop(Sender, Source: TObject; X, Y: Integer);
  243. var filepath: String;
  244.      mem: TMemoryStream; { for loading image from an archived file }
  245. begin
  246.    if Source=Sender then exit; { nowt to do }
  247.    if (Sender is TCDBImage) and (not Table1.active) then
  248.    begin
  249.      showmessage('Can''t do this unless table has been opened...');
  250.      exit;
  251.    end;
  252.  
  253.   Screen.Cursor:= crHourGlass;
  254.   if (Source = Image1) and (Sender is TCDBImage) then
  255.      CDBImage1.picture.bitmap.Assign(Image1.Picture.bitmap)
  256.   else if (Source is TCDBImage) and (Sender = Image1) then
  257.      Image1.picture.bitmap.Assign(CDBImage1.Picture.Bitmap)
  258.   else
  259.   begin   { Have we got an image? }
  260.      filepath := '';
  261.      if (Source is TListBox) and (Listbox1.selcount = 1) then
  262.       filepath:=ListBox1.Items[Listbox1.ItemIndex] { archive list }
  263.      else if (Source is TFileListBox) and (FL.selcount=1) then
  264.         filepath:=FL.Items[FL.ItemIndex]; { file list }
  265.      if LowerCase(ExtractFileExt(filepath))<>'.bmp' then
  266.      begin
  267.         MessageBeep(1);
  268.         showmessage('Must be a .BMP file...')
  269.      end else begin                             { ok, here we go... }
  270.         if Source is TListBox then { must first extract file... }
  271.         begin { Note: Registered users will get the source of two FASTER ways
  272.                                 of going about this (no expanded file needed) }
  273.           Compress1.ExpandFile(filepath,ArchiveFile.Text);
  274.           Screen.cursor := crDefault; { as our OnCheckFile sets it on }
  275.           if filepath='' then exit; { was skipped on confirmation }
  276.         end;
  277.         Screen.Cursor:= crHourGlass;
  278.         if Sender = Image1 then
  279.            Image1.Picture.Bitmap.LoadFromfile(filepath)
  280.         else
  281.            CDBImage1.Picture.Bitmap.LoadFromFile(filepath);
  282.      end; { else }
  283.   end;
  284.   if Table1.active and (Table1.State in [dsEdit]) then Table1.post; { save immediately if updated }
  285.   if not Image1.Picture.Bitmap.Empty then Memo1.visible := False; { got a piccy showing... }
  286.   Screen.Cursor:= crDefault;
  287. end;
  288.  
  289. { Examples of setting/loading/shifting CDBMemo blobs }
  290. procedure TForm1.CDBMemo1DragDrop(Sender, Source: TObject; X, Y: Integer);
  291. var filepath: String;
  292.      f: Tfilestream;
  293.      mem: TMemoryStream; { for loading text from an archived file }
  294. begin
  295.  
  296.   filepath := ''; { in case fails }
  297.   if (Source is TListBox) and (Listbox1.selcount = 1) then
  298.    filepath:=ListBox1.Items[Listbox1.ItemIndex] { archive list }
  299.   else if (Source is TFileListBox) and (FL.selcount=1) then
  300.      filepath:=FL.Items[FL.ItemIndex]; { file list }
  301.   if LowerCase(ExtractFileExt(filepath))<>'.txt' then
  302.   begin
  303.     MessageBeep(1);
  304.     showmessage('Must be a .TXT file...')
  305.   end else begin                             { ok, here we go... }
  306.     if Source is TListBox then { must first extract file... }
  307.     begin { Note: Registered users will get the source of two FASTER ways
  308.                             of going about this (no expanded file needed) }
  309.       Compress1.ExpandFile(filepath,ArchiveFile.Text);
  310.       Screen.cursor := crDefault; { as our OnCheckFile sets it on }
  311.       if filepath='' then exit; { was skipped on confirmation }
  312.     end;
  313.     Screen.Cursor:= crHourGlass;
  314.     CDBMemo1.Lines.LoadfromFile(filepath)
  315.   end;
  316.   if Table1.active and (Table1.State in [dsEdit]) then Table1.post; { save immediately }
  317.   Screen.Cursor:= crDefault;
  318. end;
  319.  
  320. procedure TForm1.CDBMemo1DragOver(Sender, Source: TObject; X, Y: Integer;
  321.   State: TDragState; var Accept: Boolean);
  322. begin
  323.   accept := (Source is TFileListBox) or (Source is TListBox);
  324. end;
  325.  
  326. procedure TForm1.CDBImage1DragOver(Sender, Source: TObject; X, Y: Integer;
  327.   State: TDragState; var Accept: Boolean);
  328. begin
  329.   accept := (Source=Image1) or (Source is TCDBImage) or
  330.      (Source is TFileListBox) or (Source is TListBox);
  331. end;
  332.  
  333. { Refreshing a CDBImage so it will be compressed (assuming previously uncompressed) }
  334. procedure TForm1.CDBImage1MouseDown(Sender: TObject; Button: TMouseButton;
  335.   Shift: TShiftState; X, Y: Integer);
  336. begin
  337.   if Button=mbRight then { ok, refresh our field }
  338.   begin
  339.      CDBImage1.CopyToClipBoard;
  340.      CDBImage1.PasteFromClipBoard;
  341.      Table1.post;
  342.   end;
  343. end;
  344.  
  345. procedure TForm1.CDBMemo1MouseDown(Sender: TObject; Button: TMouseButton;
  346.   Shift: TShiftState; X, Y: Integer);
  347. begin
  348.   if Button=mbRight then { ok, refresh our field }
  349.   begin
  350.      CDBMemo1.Lines[0]:=CDBMemo1.Lines[0]; { setting .Modified doesn't do it... }
  351.      Table1.post;
  352.   end;
  353.  
  354. end;
  355.  
  356. procedure TForm1.CMethodClick(Sender: TObject);
  357. begin
  358.   CDBIMage1.CompressionMethod := getCompressionMethod;
  359.   CDBMemo1.CompressionMethod := getCompressionMethod;
  360. end;
  361.  
  362. procedure TForm1.FormCreate(Sender: TObject);
  363. begin
  364.  
  365.  fileList := TStringList.create; { keeps track of our archive files for display etc. }
  366.  SendMessage(ListBox1.handle,LB_SetHorizontalExtent,300,LongInt(0));
  367.  saveCompressionMethod := -1; { see Listbox1.click }
  368.  showfiles; { show files in archive (if any)... }
  369.  try
  370. {$IFDEF WINDOWS}
  371.    DL.Directory := '\DELPHI\IMAGES\BACKGRND';
  372. {$ENDIF}
  373. {$IFDEF WIN32}
  374.    DL.Directory := '\Program Files\Borland\Delphi 2.0\IMAGES\BACKGRND';
  375. {$ENDIF}
  376.  except on EInOutError do ; { nowt, let it default }
  377.  end;
  378.  
  379.  try Table1.Active := True;
  380.      DataSource1.Edit;
  381.  except
  382.   on EDBEngineError do
  383.      showmessage('The BLOB compression portion of this demonstration'+#13+
  384.                  'requires that the DBDEMOS alias be set up and pointing'+#13+
  385.                  'to the BIOLIFE.DB table in \DELPHI\DEMOS\DATA.'+#13+#13+
  386.                  '-- as this is not currently the case, the BLOB demonstration'+#13+
  387.                  'is disabled.');
  388.   on EUnrecognizedCompressionMethod do
  389.      showmessage('Your BIOLIFE database appears to have been compressed with'+#13+
  390.                  'a custom compression method which cannot be recognised.'+#13+
  391.                  'Please revert to an uncompressed backup of BIOLIFE.*');
  392.  end; {try }
  393.  
  394.  if not Table1.Active then { something went wrong... }
  395.  begin
  396.      CDBImage1.visible:=False;
  397.      CDBMemo1.visible:=False;
  398.      DBNavigator1.visible:=False;
  399.      Memo1.visible:=False;
  400.      Memo2.visible := True;
  401.  end;
  402.  CMethodClick(self);  { get default compression for our database controls }
  403.  
  404. end;
  405.  
  406. function TForm1.GetDir: string; { called below and in GetDummyFileName }
  407. begin
  408.   Result := DL.Directory;
  409.   if Copy(Result,Length(Result),1)<>'\' then { not already \'d? }
  410.     Result := Result+'\';
  411. end;
  412.  
  413. procedure TForm1.archivefileChange(Sender: TObject);
  414. begin
  415.   showfiles;
  416. end;
  417.  
  418. function TForm1.getCompressionMethod: TCompressionMethod;
  419. begin
  420.    result := coNone; { default }
  421.    case CMethod.ItemIndex of
  422.      1: result := coRLE;
  423.      2: result := coLZH;
  424.    end;
  425. end;
  426.  
  427. procedure TForm1.DLDragOver(Sender, Source: TObject; X, Y: Integer;
  428.   State: TDragState; var Accept: Boolean);
  429. begin
  430.   accept := True;
  431.   if ((Sender is TDirectoryListBox) and (Source is TFileListBox)) or
  432.      (Source=Trashcan) then
  433.         accept := False; { fair enough? }
  434. end;
  435.  
  436. procedure TForm1.archivefileDragOver(Sender, Source: TObject; X,
  437.   Y: Integer; State: TDragState; var Accept: Boolean);
  438. begin
  439.   accept := True; { but... }
  440.   if ((Source is TGroupBox) and not (Sender is TGroupBox)) or
  441.          (((Sender is TEdit)or (Sender is TGroupBox)) and (Source is TListBox)) or { not from our OWN list }
  442.            (Source=Trashcan) then
  443.      accept := False;
  444. end;
  445.  
  446. { Used to create 'work' filenames for saving images and memos
  447.   from the database into our archive or to disk... }
  448. function TForm1.GetDummyFilename(generatefrom: string; ext: string): string;
  449. var spos:Integer;
  450. begin
  451.   if (generatefrom='Image') or (generateFrom='') then
  452.      generatefrom:='image'
  453.   else
  454.   begin
  455. {$IFDEF WINDOWS}
  456.      generatefrom := copy(generatefrom,1,8); { max 8 }
  457.      spos:=pos(' ',generateFrom);
  458.      while spos >0 do { eliminate spaces }
  459.      begin
  460.         delete(generatefrom,spos,1);
  461.        spos:=pos(' ',generateFrom);
  462.      end;
  463. {$ENDIF}     
  464.   end;
  465.   result := AnsiLowerCase(Getdir+generatefrom+'.'+ext);
  466. end;
  467.  
  468. function Confirmfilename(filename: String; archiving: Boolean): Boolean;
  469. var dlg: Integer;
  470. begin
  471.   Result := True; { default for archiving }
  472.   if (not Archiving) and
  473.      (MessageDlg('Save to '+filename+'?', mtConfirmation,[mbYes, mbNo], 0)<>id_Yes) then
  474.      Result := False;
  475. end;
  476.  
  477. { The handler for dropping things on the file list or archive list }
  478. procedure TForm1.handleDropField(Source: TObject; archivetoo: Boolean);
  479. var filename: String;
  480. begin
  481.   filename := ''; { in case it is NOT one of those below... }
  482.   if Source is TCDBMemo then
  483.   begin
  484.      filename := GetDummyFilename(Fishname.Text,'TXT');
  485.      if not confirmFilename(filename,archivetoo) then exit;
  486.      CDBMemo1.Lines.SaveToFile(filename);
  487.   end else if Source is TCDBImage then
  488.   begin
  489.      filename := GetDummyFilename(Fishname.Text,'BMP');
  490.      if not confirmFilename(filename,Archivetoo) then exit;
  491.      CDBImage1.Picture.Bitmap.SaveToFile(filename);
  492.   end
  493.   else
  494.    if Source = Image1 then
  495.   begin
  496.      filename := GetDummyFilename('Image','BMP');
  497.      if not confirmFilename(filename,Archivetoo) then exit;
  498.      Image1.Picture.Bitmap.SaveToFile(filename);
  499.   end;
  500.   if (filename<>'') and (ArchiveToo) then
  501.       CompressOneFile(filename);
  502. end;
  503.  
  504.  
  505. procedure TForm1.archivefileDragDrop(Sender, Source: TObject; X,
  506.   Y: Integer);
  507. begin
  508.   if Source is TFileListBox then
  509.      CompressFiles
  510.   else
  511.     HandleDropField(Source, True); { save to temp file AND archive... }
  512. end;
  513.  
  514. procedure TForm1.DLDragDrop(Sender, Source: TObject; X, Y: Integer);
  515. var dlg: Integer;
  516. begin
  517.   if Source=Sender then exit; { seems reasonable, and IS necessary }
  518.   if Source is TListBox then
  519.     ExpandDelete(cmExpand,False) { selected archive files }
  520.   else if Source=ArchiveGroup then
  521.      ExpandDelete(cmExpand,True) { all archived files }
  522.   else
  523.     HandleDropField(Source, False); { save field to a file }
  524.   FL.Update; { get up to date... }
  525. end;
  526. procedure TForm1.TrashcanDragDrop(Sender, Source: TObject; X, Y: Integer);
  527. var count: Integer;
  528.     tempBitmap: TBitMap; { just to get an empty one }
  529. begin
  530.   if Source is TListBox then
  531.     ExpandDelete(cmDelete,False)
  532.   else if Source=ArchiveGroup then
  533.      ExpandDelete(cmDelete,True) { all files }
  534.      { and strictly speaking, should now delete the archive if it is
  535.        empty, but I'll leave that as an exercise... }
  536.   else if Source is TFileListBox then { delete some or all... }
  537.   begin
  538.      for count:=0 to FL.Items.count-1 do
  539.         if FL.selected[count] and
  540.            (MessageDlg('Delete '+GetDir+FL.Items[count],mtConfirmation,[mbYes,mbNo],0)=id_Yes) then
  541.            SysUtils.DeleteFile(GetDir+FL.Items[count]);
  542.      FL.Update;
  543.   end
  544.   else if (Source is TCDBMemo) and
  545.               (MessageDlg('Cut to clipboard?',mtConfirmation,[mbYes,mbNo],0)=id_Yes) then
  546.   begin
  547.      CDBMemo1.SelectAll;
  548.      CDBMemo1.cutToClipboard { safer than .clear, for demo purposes }
  549.   end
  550.   else if (Source is TCDBImage) and
  551.             (MessageDlg('Cut to clipboard?',mtConfirmation,[mbYes,mbNo],0)=id_Yes) then
  552.       CDBImage1.cutToClipboard { not quite a delete, but just for example... }
  553.   else if Source=Image1 then
  554.   begin
  555.      tempBitMap := TBitMap.Create;
  556.      try
  557.         Image1.Picture.Bitmap.Assign(tempBitMap);
  558.         Memo1.visible := True
  559.      finally
  560.         tempBitMap.free;
  561.      end;
  562.   end;
  563.  
  564.  
  565. end;
  566.  
  567. procedure TForm1.FormDestroy(Sender: TObject);
  568. var count: Integer;
  569. begin
  570.   Compress1.FreeFileList(FileList); { free list and any file information objects in it }
  571. end;
  572.  
  573.  
  574. procedure TForm1.ListBox1Click(Sender: TObject);
  575. var cfinfo: TCompressedFileInfo;
  576. begin
  577.   if listBox1.ItemIndex >=0 then
  578.   begin
  579.      CMethod.Color := ShowFileInfoColor; { make it clear we are showing off a bit... }
  580.      Percentage.Color := ShowFileInfoColor;
  581.      Time.Color := ShowFileInfoColor;
  582.      TimeLabel.Caption := 'Full Size:';
  583.  
  584.      cfinfo:=TCompressedFileinfo(FileList.objects[listBox1.ItemIndex]); { how to get at the other stuff... }
  585.      if cfinfo.Fullsize>0 then
  586.        Percentage.caption:=IntToStr(100-100*cfinfo.CompressedSize div cfinfo.Fullsize)+'%'
  587.      else
  588.        Percentage.caption:='(empty)';
  589.      if cfinfo.locked then
  590.         Percentage.caption := Percentage.caption + ' (locked)';
  591.      Time.caption:= IntToStr((512+cfinfo.Fullsize) div 1024)+' Kb';
  592.      if saveCompressionMethod <0 then
  593.         savecompressionMethod :=cMethod.ItemIndex;
  594.      cMethod.ItemIndex :=Integer(cfinfo.CompressedMode);
  595.   end;
  596. end;
  597.  
  598. procedure TForm1.ResetFileInfo;
  599. begin
  600.   if saveCompressionMethod <0 then exit;
  601.   cMethod.ItemIndex:=savecompressionMethod;
  602.   saveCompressionMethod := -1;
  603.   CMethod.Color := clBtnFace;
  604.   Percentage.Color := clWindow;
  605.   Time.Color := clWindow;
  606.   TimeLabel.Caption := 'Time:';
  607.   showInfo; { get the right stuff too... }
  608.   Time.Caption:=''; { but this is meaningless at this point... }
  609. end;
  610.  
  611.  
  612. procedure TForm1.Table1AfterPost(DataSet: TDataset);
  613. begin
  614.   Showinfo;
  615. end;
  616.  
  617. procedure TForm1.Button1Click(Sender: TObject);
  618. begin
  619.   ShowMessage('Drag and Drop at will: compression and expansion'+#13+
  620.   'is automatic.'+#13+#13+
  621.   'Uses TCompress, TCDBMemo and TCDBImage.'+#13+#13+
  622.   'Component Registration and License: $NZ70 (appr. $US50)'+#13+
  623.   'South Pacific Information Services Ltd'+#13+
  624.   'Fax: +64-3-384-5138   Email: peter@spis.co.nz');
  625. end;
  626.  
  627. procedure TForm1.FLClick(Sender: TObject);
  628. begin
  629.   ResetFileInfo;
  630. end;
  631.  
  632. { Example of OnCheckFile user interface handling routine
  633.   Note that the V2.5 TargetPath property frequently obviates the need
  634.   for any Expand handler, but we've kept it anyway for your
  635.   info. Also, you could Set the MakeDirectories property if
  636.   the target path's should be created if required.
  637. }
  638. procedure TForm1.Compress1CheckFile(var filepath: String;
  639.   mode: TCProcessMode);
  640. var modestr: String;
  641.   dlg: Integer;
  642. begin
  643.   case mode of
  644.      cmExpand: begin
  645.                  modestr := 'Expand';
  646.                  filepath:=Getdir+extractfilename(filepath); { go where we should }
  647.                end;
  648.      cmCompress: begin
  649.                     modestr := 'Compress';
  650.                     filepath:={Getdir+}extractfilename(filepath); { use GetDir if you want full path... }
  651.                  end;
  652.      cmDelete: modestr := 'Delete';
  653.   end;
  654.   showInfo;
  655.   Screen.cursor := crDefault; { in case this is second call in a sequence }
  656.   dlg := MessageDlg(modestr+' '+filepath+'?', mtConfirmation,[mbYes, mbNo, mbCancel], 0);
  657.   case dlg of
  658.      id_No: filepath :=CompressSkipFlag; { flag 'not this one'}
  659.      id_Cancel: filepath :=CompressNoMoreFlag; { flag 'no more!' }
  660.      id_Yes: Screen.Cursor := crHourGlass; { for operation itself }
  661.   end;
  662. end;
  663.  
  664.  
  665. procedure TForm1.Panel1Click(Sender: TObject);
  666. begin
  667. ResetFileInfo;
  668. end;
  669.  
  670. procedure TForm1.FormClick(Sender: TObject);
  671. begin
  672. ResetFileInfo;
  673. end;
  674.  
  675. procedure TForm1.GroupBox1Click(Sender: TObject);
  676. begin
  677. ResetFileInfo;
  678. end;
  679.  
  680. procedure TForm1.TrashcanDragOver(Sender, Source: TObject; X, Y: Integer;
  681.   State: TDragState; var Accept: Boolean);
  682. begin
  683.   accept := True;
  684. end;
  685.  
  686. procedure TForm1.Button2Click(Sender: TObject);
  687. begin
  688. Application.HelpFile:='COMPRESS.HLP';
  689. Application.HelpJump('1050');
  690. end;
  691. end.
  692.